var valueinput,methodvalue
Page({
  data: {
    items: [
      {value: '1', name: '网易云热评'},
      {value: '2', name: '星座运势（需要输入您的星座）'},
      {value: '3', name: '藏头诗生成（请输入藏字内容，2-8个字）'},
    ],
    focus: false,
    inputValue: ''
  },
  Tianapi: function () {
    this.onLoad();
  },
  onLoad: function () {
    var that = this
	wx.setNavigationBarTitle({
      title: '趣味生成器',
    }) 
    wx.request({
      url: 'https://api.tianapi.com' + '/txapi/wanan/index',
      data: {
        key: "238c3f5c3195765876c29f3cc6bb4234" 
      },
      success: function (res) {
        if(res.data.code == 200){
        that.setData({
          content: res.data.newslist[0].content
        })
      }
      },
      fail: function (err) {
        console.log(err)
      }
    })
  },
  radioChange(e) {
    //console.log('radio发生change事件，携带value值为：', e.detail.value)
    methodvalue=e.detail.value
    const items = this.data.items
    for (let i = 0, len = items.length; i < len; ++i) {
      items[i].checked = items[i].value === e.detail.value
    }

    this.setData({
      items
    })
  },

  bindKeyInput:function (e) {
  valueinput=e.detail.value
  console.log(valueinput)
  },

  method(){
    if(methodvalue=="1"){
      this.m1();
    }
    if(methodvalue=="2"){
      this.m2();
    }
    if(methodvalue=="3"){
      this.m3();
    }
  },

  m1(){
    var that= this
    wx.request({
      url: 'http://api.tianapi.com/hotreview/index?key=238c3f5c3195765876c29f3cc6bb4234', 
      method: 'POST', 
      success: function (res) {
        if(res.data.code == 200){
       console.log(res.data)
         }
         that.setData({
          content1:"热评内容:"+res.data.newslist[0]["content"]+"取自歌曲："+res.data.newslist[0]["source"]
         })  
      },
      fail: function (err) {
        console.log(err)
      }
    })
  },
  m2(){
    var that= this
    wx.request({
      url: 'http://api.tianapi.com/star/index?key=238c3f5c3195765876c29f3cc6bb4234&astro='+valueinput, 
      method: 'POST', 
      success: function (res) {
        if(res.data.code == 200){
       console.log(res.data)
         }
         that.setData({
          content1:res.data.newslist[0]["type"]+res.data.newslist[0]["content"],
          content2:res.data.newslist[1]["type"]+res.data.newslist[1]["content"],
          content3:res.data.newslist[2]["type"]+res.data.newslist[2]["content"],
          content4:res.data.newslist[3]["type"]+res.data.newslist[3]["content"],
          content5:res.data.newslist[4]["type"]+res.data.newslist[4]["content"],
          content6:res.data.newslist[5]["type"]+res.data.newslist[5]["content"],
          content7:res.data.newslist[6]["type"]+res.data.newslist[6]["content"],
          content8:res.data.newslist[7]["type"]+res.data.newslist[7]["content"],
          content9:res.data.newslist[8]["type"]+":"+res.data.newslist[8]["content"]
         })  
      },
      fail: function (err) {
        console.log(err)
      }
    })
  },
  m3(){
    var that= this
    wx.request({
      url: 'http://api.tianapi.com/cangtoushi/index?key=238c3f5c3195765876c29f3cc6bb4234&word='+valueinput, 
      method: 'POST', 
      success: function (res) {
        if(res.data.code == 200){
       console.log(res.data)
         }
         that.setData({
          content1:res.data.newslist[0]["list"]
         })  
      },
      fail: function (err) {
        console.log(err)
      }
    })
  },

})
